#include "BitWriter.h"

BitWriter::BitWriter(char* source, int actualPos) {
        this->toWrite = source;
        this->actualPos = actualPos;
}

void BitWriter::putBit(bool state){
        if (state)
                this->toWrite[this->actualPos++] = '1';
        else
                this->toWrite[this->actualPos++] = '0';
}

long BitWriter::toLong(){
        long value = 0;
        int size = this->actualPos - 1;
        for (int a = size; a >= 0; a--){
                if(this->toWrite[a] == '1')
                        value += (1 << (size - a));
        }

        return value;
}

void BitWriter::close(){
        this->toWrite[this->actualPos] = '\0';
}

